package com.ohos.connent.modelcloud.biz.modular.pro.controller;

import cn.hutool.core.lang.tree.Tree;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ohos.connent.modelcloud.biz.modular.pro.param.BizProCategoryDictAddParam;
import com.ohos.connent.modelcloud.biz.modular.pro.param.BizProCategoryDictIdParam;
import com.ohos.connent.modelcloud.biz.modular.pro.param.BizProCategoryDictTreeParam;
import com.ohos.connent.modelcloud.biz.modular.pro.service.BizProCategoryDictService;
import com.ohos.connent.modelcloud.common.annotation.CommonLog;
import com.ohos.connent.modelcloud.common.pojo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author: ChenJiaHao
 * @Date: 2024/6/4 18:48
 * @Description:
 */
@Api(tags = "品类树控制器")
@ApiSupport(author = "OHOSCONNECT_TEAM", order = 3)
@RestController
@RequestMapping(value = "/api/v1/model/biz/pro-category-dict")
@Validated
public class BizProCategoryDictController {

    @Resource
    private BizProCategoryDictService bizProCategoryDictService;

    /**
     * 获取品类树
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取品类树")
    @PostMapping("/tree")
    public CommonResult<List<Tree<String>>> tree(@RequestBody @Valid BizProCategoryDictTreeParam bizProCategoryDictTreeParam) {
        return CommonResult.data(bizProCategoryDictService.tree(bizProCategoryDictTreeParam));
    }

    /**
     * 新增品类字典目录
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("新增品类字典目录")
    @CommonLog("新增品类字典目录")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid BizProCategoryDictAddParam bizProCategoryAddParam) {
        bizProCategoryDictService.add(bizProCategoryAddParam);
        return CommonResult.ok();
    }

    /**
     * 删除品类字典目录
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除品类字典目录")
    @CommonLog("删除品类字典目录")
    @GetMapping("/delete")
    public CommonResult<String> delete(@Valid BizProCategoryDictIdParam bizProCategoryDictIdParam) {
        bizProCategoryDictService.delete(bizProCategoryDictIdParam);
        return CommonResult.ok();
    }
}
